<template>
  <div>
    <div border="~" p="y-12" rounded="md" m="b-12">
      <p text="4xl">{{ getScore() }}</p>
    </div>

    <button @click="reStart" class="btn">重新开始</button>
  </div>
</template>

<script setup lang="ts">
import { answerStore } from '@/store/modules/answer';

const router = useRouter();
const store = answerStore();
const { answerList } = storeToRefs(store);

const getScore = () => {
  let sum = 0;
  answerList.value.forEach((item) => {
    if (item.is_right) {
      sum += item.grade;
    }
  });
  return sum;
};

const reStart = () => {
  store.$reset();
  router.push('/');
};
</script>

<style scoped></style>
